using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Metropolicity
{
    class PowerNode : InteractableGameObject
    {
        protected PlayScene parent;
        public EnergyCell energyCell;
        public Boolean selected;
        protected int energyRespawnTime;//in milliseconds
        protected int timeSinceLastSpawn; // in milliseconds
        public Rectangle collisionRectangle;
        public Texture2D testPixels;

        public PowerNode(String texturePath, Vector2 position, PlayScene parent)
            : base(texturePath, position)
        {
            selected = false;
           // zindex += .002f;
            timeSinceLastSpawn = 0;
            this.parent = parent; //inheriting the parent allows it to call the parent's content to load content
        }
        public void timeKeepsOnTicking(GameTime gametime) //into the fuuuutuuuuuuuuure!!
        {
            if (energyCell == null)
            {
                timeSinceLastSpawn += (int)(Math.Round(gametime.ElapsedGameTime.TotalMilliseconds));
                if (timeSinceLastSpawn >= energyRespawnTime)
                {
                    energyCell = createEnergy();
                    timeSinceLastSpawn = 0;
                }
            }
        }
        public override void LoadContent(ContentManager content)
        {
            testPixels = content.Load<Texture2D>("testPixel");
            
            base.LoadContent(content);
            if (texturePath != null)
            {
                this.rectangle = new Rectangle(
                (int)position.X,
                (int)position.Y - (int)(texture.Height - 32),
                texture.Width,
                texture.Height
                );
                Console.Write(rectangle);
                collisionRectangle = new Rectangle(
                    (int)position.X,
                    (int)rectangle.Y + (int)(texture.Height - 32),
                    texture.Width,
                    32
                    );
            }
        }
        public override void Update(GameTime gameTime)
        {

        }
        public override void ScaleUpdate()
        {
            base.ScaleUpdate();
            rectangle = new Rectangle((int)position.X, (int)position.Y, (int)(texture.Width * scale), (int)((texture.Height - 32) * scale));
            collisionRectangle = new Rectangle((int)position.X, (int)position.Y, (int)(texture.Width * scale), (int)(32 * scale));
           
        }
        public virtual EnergyCell createEnergy()
        {
            return null;
        }
        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(testPixels, collisionRectangle, Color.Blue);
            if (energyCell != null)
                energyCell.Draw(spriteBatch);
            base.Draw(spriteBatch);
        }
        public virtual void stormStarts() { }
        public virtual void stormEnds() { }
    }
}
